//
//  RemindViewController.m
//  liangyi
//
//  Created by 张水 on 17/1/5.
//  Copyright © 2017年 yswh. All rights reserved.
//

#import "RemindViewController.h"
#import "RemindCell.h"
@interface RemindViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) NSMutableArray *dataArr;

@property(nonatomic,assign)int  pageNo;

@property(nonatomic,strong) UITableView *tableView;

@end

@implementation RemindViewController

static NSString *RemindCellID = @"RemindCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataArr = [NSMutableArray array];
    self.pageNo = 1;
    self.title =  @"温馨提醒";
    [self initUI];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadCommitList];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)initUI{
    
    self.tableView  = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = YES;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[RemindCell class] forCellReuseIdentifier:RemindCellID];
    [CommonMethod hiddleExtendCellFromTableview:self.tableView];
    [self.view addSubview:self.tableView];
    
 
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   RemindCell *remindCell = [tableView dequeueReusableCellWithIdentifier:RemindCellID forIndexPath:indexPath];
    if (!remindCell){
        remindCell = [remindCell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:RemindCellID];
    }
    remindCell.selectionStyle = UITableViewCellSeparatorStyleNone;
    remindCell.model = self.dataArr[indexPath.section];
    return remindCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%ld",(long)indexPath.row);
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

-(void)loadCommitList{
    NSString *url = [BASEURL  stringByAppendingString:kURL_Remind];
    NSDictionary *dict = @{@"pageNo":[NSString stringWithFormat:@"%d",self.pageNo]};
    NSString *jsonString = [NSString dictionaryToJson:dict];
    NSString *AESString = [NSString AES128Encrypt:jsonString];
    NSDictionary *parameters = @{@"parameters":AESString,
                                 @"login":[NSString  AES128Encrypt:[NSString stringWithFormat:@"%@@@%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"userid"],ApplicationDelegate.deviceID]]};
    NSLog(@"%@",dict);
    [AppNetwork requestWithPath:url parameters:parameters  success:^(id responseObject) {
        NSLog(@"%@",responseObject);
        NetworkModel *network = [NetworkModel mj_objectWithKeyValues:responseObject];
        NSInteger code = network.code.integerValue;
        if (code == 0){
            if ([network.dataObject isKindOfClass:[NSArray class]]){
                [self.dataArr removeAllObjects];
                NSArray *arr = [Remind mj_objectArrayWithKeyValuesArray:network.dataObject];
                [self.dataArr addObjectsFromArray:arr];
                NSLog(@"%ld",(unsigned long)self.dataArr.count);
                [self.tableView reloadData];
            }
            
        }else{
            [CustomProgressHUD showErrorWithStatus:network.errorDescription];
        }
    } failure:^(id error) {
        [CustomProgressHUD showErrorWithStatus:k_NetWorkStatus_Error];
    }];
}
@end

